package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dominio.Agente;

/**
 * Servlet implementation class AtualAgenteServlet
 */
public class AtualAgenteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		/*Agente agente = null;
		
		String login = request.getParameter("loginUsuario");
		
		AgenteDao agenteDao = new AgenteDao();
		try {
			agente = agenteDao.findAgenteByUserLogin(login);
		} catch (DaoException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		
		Agente agente = (Agente) request.getSession().getAttribute("agente");
		
		if(agente != null) {
			response.getWriter().print("Agente = " +
										agente.getNome() +
										"\nSalario = " +
										agente.getSalario());
		} else {
			response.getWriter().print("erro");
		}
		response.getWriter().flush();
		response.getWriter().close();
	}

}
